package org.noka.bver;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

import org.nokatag.system.Function;
import org.nokatag.tagjava.NokaTag;

public class BverTag extends NokaTag{
	private static final long serialVersionUID = 9114633711896935282L;
	private Integer width = 260;
	private String name = null;
	private String id = null;
	private String title = null;
	private String stitle = null;
	
	public int doStartTag()throws JspException{
		
		JspWriter jspOut = pageContext.getOut();
		HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
		StringBuilder stringBuilder = new StringBuilder();
		stringBuilder.append(potjs(request));
		stringBuilder.append(codeBverJS(request));//
		String basePath = basepath(request);
		String v1 = Function.lung(request,"org_nokatag_codebver");
		String v2 = Function.lung(request,"org_nokatag_codebver2");
		if(null!=title)
			v1 = title;
		if(null!=stitle)
			v2=stitle;
		stringBuilder.append("<div style=\"clear: both;\"></div><div id=\""+id+"_div\" style=\"width:"+width+"px;height:30px;position: relative;\"></div>");
		stringBuilder.append("<script type=\"text/javascript\">\n");
		stringBuilder.append("Event.observe(document, 'dom:loaded', function() {");
		stringBuilder.append("var nslide"+id+" = new NKSlide({id:'"+id+"',v1:'"+v1+"',v2:'"+v2+"',width:'"+width+"',rurl:'"+basePath+"',name:'"+name+"'});");
		stringBuilder.append("nslide"+id+".show();");
		stringBuilder.append("});");
		stringBuilder.append("</script>\n");
		try {
			jspOut.write(stringBuilder.toString());
		} catch (IOException e) {
			e.printStackTrace();
		}
		return EVAL_BODY_INCLUDE;
	}

	public Integer getWidth() {
		return width;
	}

	public void setWidth(Integer width) {
		this.width = width;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getId() {
		return id;
	}

	public void setId(String id) {
		this.id = id;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getStitle() {
		return stitle;
	}

	public void setStitle(String stitle) {
		this.stitle = stitle;
	}
}
